package cn.shengchao.dubbo.bi;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import cn.shengchao.base.enums.DisEnableStatusEnum;
import cn.shengchao.base.enums.GenderEnum;
import cn.shengchao.examstar.distribute.infrastrure.po.*;
import cn.shengchao.examstar.rpc.base.TransResult;
import cn.shengchao.examstar.rpc.distribute.cs.UserCs;
import cn.shengchao.examstar.distribute.infrastrure.service.*;
import cn.shengchao.examstar.distribute.model.DistributeNodeRoleChainExistModel;
import cn.shengchao.examstar.distribute.ohs.local.appservice.DistributeNodeRoleChainDomainService;
import cn.shengchao.examstar.distribute.ohs.local.appservice.DistributeNodeRoleChainExistLoader;
import cn.shengchao.examstar.rpc.distribute.dto.*;
import cn.shengchao.examstar.rpc.distribute.enums.*;
import cn.shengchao.examstar.rpc.uddsys.bi.PlatformUserArchBI;
import cn.shengchao.examstar.rpc.uddsys.dto.PlatformUserInfoDto;
import cn.shengchao.examstar.rpc.uddsys.req.DistributeNodeInfoEditReq;
import cn.shengchao.examstar.rpc.uddsys.req.DistributeNodeInfoStateReq;
import cn.shengchao.examstar.rpc.uddsys.dto.DistributeUserBankSaveDto;
import cn.shengchao.examstar.rpc.uddsys.resp.DistributeUserBankVo;
import cn.shengchao.examstart.user.acl.ports.repositories.IDeptRepository;
import cn.shengchao.examstart.user.acl.ports.repositories.IUserRepository;
import cn.shengchao.examstart.user.domain.entity.Dept;
import cn.shengchao.examstart.user.domain.entity.PlatformUser;
import cn.shengchao.examstart.user.domain.entity.User;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional;
import top.continew.starter.core.exception.BaseException;

import java.math.BigDecimal;
import java.util.List;

/**
 * @program: examstarapi
 * @description: 分销用户体系的整合接口
 * @author: Xiong weiqiang
 * @create: 2025-03-30 00:11
 */
@DubboService
@RequiredArgsConstructor
public class PlatformUserArchBIService implements PlatformUserArchBI {
    private final IUserRepository userRepository;
    private final IDeptRepository deptRepository;
    private final DistributeRoleDefaultPercentService distributeRoleDefaultPercentService;
    private final DistributeDeptUserRoleBindService distributeDeptUserRoleBindService;
    private final DistributeDeptInfoService distributeDeptInfoService;
    private final DistributeNodeRoleChainExistLoader distributeNodeRoleChainExistLoader;
    private final DistributeNodeRoleChainDomainService distributeNodeRoleChainDomainService;
    private final DistributeNodeInfoService distributeNodeInfoService;
    private final DistributeUserBankService distributeUserBankService;
    private final InviteUnifiedCreateProcessor inviteUnifiedCreateProcessor;
    @Transactional
    @Override
    public void editDistributeUserStablePercent(DistributeNodeInfoPercentDto distributeUserInfoPercentDto) {
        DistributeNodeRoleChainExistModel existModel=distributeNodeRoleChainExistLoader.loadModelByUserIdByDeptChain(distributeUserInfoPercentDto.getUserId(), DistributeTypeEnum.TYPE_SALE);
        if (existModel==null||existModel.getDistributeNodeRole()==null){
            throw new BaseException("修改用户分成时发生错误：用户分销角色没有找到");
        }else {
            if (distributeUserInfoPercentDto.getPercentStable()==null||distributeUserInfoPercentDto.getPercentStable().doubleValue()>50){
                throw new BaseException("修改用户分成时发生错误：设置比例不合适"+distributeUserInfoPercentDto.getPercentStable());
            }else {
                distributeNodeRoleChainDomainService.editDistributeUserStablePercent(distributeUserInfoPercentDto);
            }
        }

    }

    @Override
    public void updateNodeState(DistributeNodeInfoStateReq distributeNodeInfoStateReq) {
        DistributeTypeEnum distributeTypeEnum = DistributeTypeEnum.getByType(distributeNodeInfoStateReq.getDistributeType());
        if (distributeTypeEnum==null){
            throw new BaseException("编辑代理用户状态时发生错误：分销用户类型错误");
        }
        DisEnableStatusEnum disEnableStatusEnum=DisEnableStatusEnum.getByValue(distributeNodeInfoStateReq.getEnableStatus());
        if (disEnableStatusEnum==null){
            throw new BaseException("编辑代理用户状态时发生错误：分销用户上传状态错误");
        }
        DistributeNodeInfo distributeNodeInfo=distributeNodeInfoService.getNodeInfoForUser(distributeNodeInfoStateReq.getUserId(), distributeTypeEnum);
        //改状态不影响链，只影响分成
        if (distributeNodeInfo==null){
            throw new BaseException("编辑代理用户状态时发生错误：分销用户不存在");
        }else{
            distributeNodeInfoService.update(Wrappers.lambdaUpdate(DistributeNodeInfo.class)
                    .eq(DistributeNodeInfo::getId, distributeNodeInfo.getId())
                    .set(DistributeNodeInfo::getEnableStatus, distributeNodeInfoStateReq.getEnableStatus())

            );
        }
    }

    @Override
    public void updateNodeInfo(DistributeNodeInfoEditReq distributeNodeInfoEditReq) {
        DistributeTypeEnum distributeTypeEnum = DistributeTypeEnum.getByType(distributeNodeInfoEditReq.getDistributeType());
        if (distributeTypeEnum==null){
            throw new BaseException("编辑代理用户时发生错误：分销用户类型错误");
        }

        DistributeNodeInfo distributeNodeInfo=distributeNodeInfoService.getNodeInfoForUser(distributeNodeInfoEditReq.getUserId(), distributeTypeEnum);
        if (distributeNodeInfo==null){
            throw new BaseException("编辑代理用户时发生错误：分销用户不存在");
        }else{
            distributeNodeInfoService.update(Wrappers.lambdaUpdate(DistributeNodeInfo.class)
                    .eq(DistributeNodeInfo::getId, distributeNodeInfo.getId())
                    .set(StrUtil.isNotBlank(distributeNodeInfoEditReq.getShortName()),DistributeNodeInfo::getShortName, distributeNodeInfoEditReq.getShortName())
                    .set(StrUtil.isNotBlank(distributeNodeInfoEditReq.getFullName()),DistributeNodeInfo::getFullName, distributeNodeInfoEditReq.getFullName())
                    .set(StrUtil.isNotBlank(distributeNodeInfoEditReq.getContactMan()),DistributeNodeInfo::getContactMan, distributeNodeInfoEditReq.getContactMan())
                    .set(StrUtil.isNotBlank(distributeNodeInfoEditReq.getContactPhone()),DistributeNodeInfo::getContactPhone, distributeNodeInfoEditReq.getContactPhone())
                    .set(StrUtil.isNotBlank(distributeNodeInfoEditReq.getHeadImgUrl()),DistributeNodeInfo::getHeadImageUrl, distributeNodeInfoEditReq.getHeadImgUrl())
                    .set(StrUtil.isNotBlank(distributeNodeInfoEditReq.getPInLaw()),DistributeNodeInfo::getPInLaw, distributeNodeInfoEditReq.getPInLaw())
                    .set(StrUtil.isNotBlank(distributeNodeInfoEditReq.getLicNo()),DistributeNodeInfo::getLicNo, distributeNodeInfoEditReq.getLicNo())
            );
        }
    }

    /**
     * method : createPlatformUser
     * description : 后台添加普通用户，如果是学员之间的邀请关系，也可以调用，归为平台的最终收益
     * （不过平台不会做服务，一般是要分配服务用户，所以平台应该得分配给营销链体系做服务， 收益还是会给营销链体系做服务）
     * 普通用户，邀请关系归属平台，分销关系归属平台，部门不分配
     * 学员默认是DEPT -1 ,role -1
     * 
     * @param platformUserInfoDto \{@link PlatformUserInfoDto \}
     * @return : cn.shengchao.examstar.uddsys.rpc.dto.PlatformUserInfoDto
     * @author : Xiong weiqiang
     * @CreateDate : 2025-03-30 00:30:16
     *
     * @Reviewed :
     * @UpdateLog : Name Date Reason/Contents
     *            ---------------------------------------
     *            **** **** ****
     *
     */
    @Transactional
    @Override
    public PlatformUserInfoDto createPlatformUser(PlatformUserInfoDto platformUserInfoDto) {
        List<User> userList = userRepository.selectByPhone(platformUserInfoDto.getPhone());
        if (CollUtil.isNotEmpty(userList)) {
            throw new BaseException("新建平台学员用户时发生错误：手机号码已存在");
        }
        GenderEnum genderEnum = GenderEnum.ofValue(platformUserInfoDto.getGender());
        PlatformUser user = new PlatformUser();
        user.setGender(genderEnum);
        user.setNickname(platformUserInfoDto.getNickname());
        user.setUsername(platformUserInfoDto.getPhone());
        user.setPhone(platformUserInfoDto.getPhone());
        user.setPassword(platformUserInfoDto.getPhone());
        user = userRepository.savePlatformUser(user);
        platformUserInfoDto.setId(user.getId());
        UserInviteDto userInviteDto = new UserInviteDto();
        userInviteDto.setUserId(user.getId());
        userInviteDto.setInviteUserId(ObjUtil.defaultIfNull(platformUserInfoDto.getInviteUserId(), UserCs.PLATFORM_USER_ID));
        userInviteDto.setDistributeUserId(UserCs.PLATFORM_USER_ID);
        inviteUnifiedCreateProcessor.savePlatformUserInviteRecord(userInviteDto);
        return platformUserInfoDto;
    }

    /**
     * method : createSaleDistributeMemberAndRoleChain
     * description :
     * description : 成为平台会员（成为会员的条件：必须是学员或者是在营销体系里员工，不然的话没有必要）
     * 注意：如果是平台发展的会员，那么不能分配给加盟商，不然平台收益受损失。 那么平台要不要杜绝呢？
     * 
     * @param distributePersonUserCreateDto \{@link DistributePersonUserCreateDto \}
     * @author : Xiong weiqiang
     * @CreateDate : 2025-03-30 15:36:05
     *
     * @Reviewed :
     * @UpdateLog : Name Date Reason/Contents
     *            ---------------------------------------
     *            **** **** ****
     *
     */
    @Transactional
    @Override
    public TransResult<String> createSaleDistributeMemberAndRoleChain(DistributePersonUserCreateDto distributePersonUserCreateDto) {
        DistributeRoleDefaultPercent distributeRoleDefaultPercent = distributeRoleDefaultPercentService
            .getSalePercentByRoleCode(DistributeSaleRoleEnum.ROLE_SLMB.getCode());
        if (distributeRoleDefaultPercent == null || distributeRoleDefaultPercent.getPercentStable() == null) {
            return TransResult.fail("创建会员出错：查询会员默认分成比例错误");
        }

        TransResult<DistributeNodeRoleChainExistModel> checkSaleNodeCreate = distributeNodeRoleChainExistLoader
            .checkSaleNodeCreate(distributePersonUserCreateDto.getUserId(), DistributeSaleRoleEnum.ROLE_SLMB);
        Dept dept = null;
        Long upLevelUserId=null;
        if (checkSaleNodeCreate.getSuccess()) {
            //如果是小程序来的，没有上级指定
            if (distributePersonUserCreateDto.getUpLevelUserId()==null){
                if (StrUtil.isBlank(distributePersonUserCreateDto.getFullName())){
                    User user=userRepository.of(distributePersonUserCreateDto.getUserId());
                    distributePersonUserCreateDto.setFullName(user.getName());
                }
                DistributeNodeRoleChainExistModel existModel=distributeNodeRoleChainExistLoader.loadModelByUserId(distributePersonUserCreateDto.getUserId(), DistributeTypeEnum.TYPE_SALE.getType());
                if (!existModel.isExist()){
                    //原来是学员，不存在分销关系
                    //查邀请关系，正常情况下，按当前业务模式所有用户都应该有邀请关系，如果没有，那么设置为平台邀请
                    InviteUnifiedCheckDto inviteUnifiedCheckDto=inviteUnifiedCreateProcessor.getInviteUnifiedCheckDto(distributePersonUserCreateDto.getUserId());
                    //如果邀请关系不存在，或者分销企微服务关系邀请关系不相同，数据错乱，不让创建会员，不然会员有可能挂错。需要联系后台把用户的邀请服务关系调整统一后再升级。
                    if (inviteUnifiedCheckDto!=null){
                        if (!UserCs.PLATFORM_USER_ID.equals(inviteUnifiedCheckDto.getFinalDistributeUserId())){
                            distributePersonUserCreateDto.setUpLevelUserId(inviteUnifiedCheckDto.getFinalDistributeUserId());
                        }else {
                            if (!UserCs.PLATFORM_USER_ID.equals(inviteUnifiedCheckDto.getServiceDistributeUserId())){
                                distributePersonUserCreateDto.setUpLevelUserId(inviteUnifiedCheckDto.getServiceDistributeUserId());
                            }else {
                                distributePersonUserCreateDto.setUpLevelUserId(UserCs.PLATFORM_USER_ID);
                            }
                        }

                    }

                    //处理分销最终上级。加盟商体系里会员上级总是加盟商。
                    if (DistributeSaleRoleEnum.ROLE_DSPD.getCode().equals(inviteUnifiedCheckDto.getFinalUserDistributeCode())){
                        //原来是学员升会员的最终收益是加盟商，那么上级就是加盟商
                        distributePersonUserCreateDto.setUpLevelUserId(inviteUnifiedCheckDto.getFinalDistributeUserId());
                    }else {
                        //不是加盟商，那么就是平台会员，没别的情况
                        distributePersonUserCreateDto.setUpLevelUserId(UserCs.PLATFORM_USER_ID);
                    }
                    //
                    //前面判断过最终收益人，所以不用再判断了,会员客服又由员工发展（包括员工发展的会员客服关系还是员工的），客服关系直接继承
                    InviteUnifiedCheckDto slmbInviteUnifiedCheckDto=inviteUnifiedCreateProcessor.getInviteUnifiedCheckDto(inviteUnifiedCheckDto.getServiceUserId());
                    if (DistributeSaleRoleEnum.ROLE_DSPD_EMP.getCode().equals(slmbInviteUnifiedCheckDto.getServiceUserDistributeCode())){
                        //会员不一定是由自己服务，有可能是发展自己的加盟商员工（加盟商受益，总要派个人管理旗下会员的客服），也有可能是平台会员（平台有可能帮忙管理）
                        //考虑来考虑去：会员就是有能力搞客服就搞，没能力搞客服的，就是上面的服务节点搞客服，要么是加盟商搞客服，要么是平台搞客服。
                        //特殊个例1：员工发展的会员，又发展会员，那么客服邀请人还得是员工，通过会员的客服继承而来。就是员工发展会员下再发展会员，还是员工服务。
                        //特殊个例2：平台会员发展会员，那么客服邀请人还得是平台，通过平台会员的客服继承而来（平台会员初始化的时候是自己客服，但是否由自己做客服不一定，可能由平台服务）
                        inviteUnifiedCreateProcessor.processSlmbServiceInviteExtend(distributePersonUserCreateDto.getUserId(),slmbInviteUnifiedCheckDto);
                    }else {
                        //邀请人不是加盟商员工的，原来关系不变。
                        System.out.println("不是加盟商员工，原来服务关系不变"+ JSONUtil.toJsonStr(slmbInviteUnifiedCheckDto));
                    }
                }else{
                    //如果本身是员工
                    if (existModel.getDistributeNodeInfo().getDistributeRoleCode().equals(DistributeSaleRoleEnum.ROLE_DSPD_EMP.getCode())){
                        //设置上级为当前用户的上级
                        distributePersonUserCreateDto.setUpLevelUserId(existModel.getUpLevelNodeInfo().getUserId());
                        distributePersonUserCreateDto.setFullName(existModel.getDistributeNodeInfo().getFullName());
                        distributePersonUserCreateDto.setShortName(existModel.getDistributeNodeInfo().getShortName());
                        distributePersonUserCreateDto.setContactPhone(existModel.getDistributeNodeInfo().getContactPhone());
                        distributePersonUserCreateDto.setContactMan(existModel.getDistributeNodeInfo().getContactMan());
                    }else {
                        // 不能有别的分销角色
                        return TransResult.fail("创建会员出错：用户本身存在分销角色"+existModel.getDistributeNodeInfo().getDistributeRoleCode());
                    }
                }
            }
            //这个地方是把用户原先的邀请修改为会员收益，
            // 目前考虑的用户都是分销用户加的，不能随便改。
//            userInviteService.batchUpdateUserInviteRecord(distributePersonUserCreateDto.getUserId());
            if (distributePersonUserCreateDto.getUpLevelUserId().equals(UserCs.PLATFORM_USER_ID)){
                upLevelUserId = UserCs.PLATFORM_USER_ID;
                //平台默认的会员部门
                dept = deptRepository.getDeptById(DistributeDeptInnerRootEnum.YSXG_SLMB.getDeptId());
                if (dept == null) {
                    return TransResult.fail("创建会员出错：员工升会员未查询到平台会员部门");
                }
            }else {
                //如果是员工升会员，处理员工的原有上级部门关系
                if ("1".equals(checkSaleNodeCreate.getMessage())) {
                    DistributeNodeRoleChainExistModel existModel = checkSaleNodeCreate.getData();
                    //用户原来不应该有平台上级关系
                    if (UserCs.PLATFORM_USER_ID.equals(existModel.getUpLevelNodeInfo().getUserId())){
                        return TransResult.fail("创建会员出错：创建会员时，用户不应该有平台的挂载关系");
                    }
                }
                upLevelUserId = distributePersonUserCreateDto.getUpLevelUserId();
                //新上级用户的部门
                Long deptId = distributeDeptUserRoleBindService.getDeptBindIdForUser(upLevelUserId, DistributeTypeEnum.TYPE_SALE);
                dept = deptRepository.getDeptById(deptId);
                if (dept == null) {
                    return TransResult.fail("创建会员出错：会员未查询到上级用户部门对象");
                }
            }
            //如果是加盟商，上级还是加盟商部门的管理员，不是的话那么上级就是平台管理员。
            DistributeDeptInfo distributeDeptInfo = distributeDeptInfoService.getOne(Wrappers.lambdaQuery(DistributeDeptInfo.class)
                    .eq(DistributeDeptInfo::getDeptId, dept.getId()).eq(DistributeDeptInfo::getDataStatus, DistributeDataStatusEnum.STATUS_CURT.getStatus())
            );
            if (distributeDeptInfo == null) {
                return TransResult.fail("创建会员出错：会员未查询到会员部门");
            }

            //切换分销关系的部门。
            userRepository.updateUserDept(distributePersonUserCreateDto.getUserId(), dept.getId());
            distributeDeptUserRoleBindService
                .processUserDeptRole(DistributeTypeEnum.TYPE_SALE, distributePersonUserCreateDto.getUserId(), dept
                    .getId(), SysRoleDistributeBindEnum.RB_MARKET_MEMBER
                        .getSysRoleCode(), DistributeSaleRoleEnum.ROLE_SLMB.getCode());
            DistributeNodeBaseCreateDto distributeNodeBaseCreateDto = DistributeNodeBaseCreateDto.builder()
                .userType(DistributeNodePropEnum.TYPE_P.getProp())
                .distributeType(DistributeTypeEnum.TYPE_SALE.getType())
                .userId(distributePersonUserCreateDto.getUserId())
                .adminUserId(distributePersonUserCreateDto.getUserId())
                .percentStable(distributeRoleDefaultPercent.getPercentStable())
                .distributeRoleCode(DistributeSaleRoleEnum.ROLE_SLMB.getCode())
                .distributeRoleLevel(DistributeSaleRoleEnum.ROLE_SLMB.getDistributeLevel())
                .upLevelUserId(upLevelUserId)
                .build();
            distributeNodeRoleChainDomainService
                .createDistributeNodeAndRoleChainAfterClean(distributeNodeBaseCreateDto);
            updateNodeInfoAfterCreate(distributePersonUserCreateDto, DistributeTypeEnum.TYPE_SALE.getType());
        } else {
            return TransResult.fail(checkSaleNodeCreate.getMessage());
        }
        return TransResult.success("会员创建成功");
    }

    /**
     * method : createSaleDistributeJmsygAndRoleChain
     * description : 成为加盟商的员工
     * 注意：会员不能成为加盟店员工，加盟商员工可以升级会员。会员挂加盟商等于挖平台的墙角
     * 
     * @param distributePersonUserCreateDto \{@link DistributePersonUserCreateDto \}
     * @return : cn.shengchao.examstar.base.TransResult<java.lang.String>
     * @author : Xiong weiqiang
     * @CreateDate : 2025-03-30 23:45:25
     *
     * @Reviewed :
     * @UpdateLog : Name Date Reason/Contents
     *            ---------------------------------------
     *            **** **** ****
     *
     */
    @Transactional
    @Override
    public TransResult<String> createSaleDistributeJmsygAndRoleChain(DistributePersonUserCreateDto distributePersonUserCreateDto) {
        TransResult<DistributeNodeRoleChainExistModel> checkSaleNodeCreate = distributeNodeRoleChainExistLoader
            .checkSaleNodeCreate(distributePersonUserCreateDto.getUserId(), DistributeSaleRoleEnum.ROLE_DSPD_EMP);
        if (checkSaleNodeCreate.getSuccess()) {
            DistributeNodeRoleChainExistModel existModel = distributeNodeRoleChainExistLoader
                .loadModelByUserIdByDeptChain(distributePersonUserCreateDto.getUpLevelUserId(), DistributeTypeEnum.TYPE_SALE);
            if (existModel.getDistributeNodeInfo() != null && existModel.getDistributeNodeInfo()
                .getDistributeRoleCode()
                .equals(DistributeSaleRoleEnum.ROLE_DSPD.getCode())) {
                //加盟商的部门
                Long deptId = distributeDeptUserRoleBindService.getDeptBindIdForUser(distributePersonUserCreateDto
                    .getUpLevelUserId(), DistributeTypeEnum.TYPE_SALE);
                if (deptId == null) {
                    return TransResult.fail("创建加盟商员工出错：未查询到加盟商部门id");
                }
                //如果是加盟商，上级还是加盟商部门的管理员，不是的话那么上级就是平台管理员。
//                DistributeDeptInfo distributeDeptInfo = distributeDeptInfoService.getById(deptId);
                DistributeDeptInfo distributeDeptInfo = distributeDeptInfoService.getOne(Wrappers.lambdaQuery(DistributeDeptInfo.class)
                        .eq(DistributeDeptInfo::getDeptId, deptId).eq(DistributeDeptInfo::getDataStatus,DistributeDataStatusEnum.STATUS_CURT.getStatus())
                );
                if (distributeDeptInfo == null) {
                    return TransResult.fail("创建加盟商员工出错：未查询到加盟商部门");
                }
                //修改邀请关系，贡献给加盟商
                UserInviteDto userInviteDto=new UserInviteDto();
                userInviteDto.setUserId(distributePersonUserCreateDto.getUserId());
                userInviteDto.setInviteUserId(distributePersonUserCreateDto.getUpLevelUserId());
                userInviteDto.setDistributeUserId(distributePersonUserCreateDto.getUpLevelUserId());
                inviteUnifiedCreateProcessor.savePlatformUserInviteRecord(userInviteDto);
                //切换分销关系的部门。
                userRepository.updateUserDept(distributePersonUserCreateDto
                        .getUserId(), distributeDeptInfo.getDeptId());
                distributeDeptUserRoleBindService
                    .processUserDeptRole(DistributeTypeEnum.TYPE_SALE, distributePersonUserCreateDto
                        .getUserId(), distributeDeptInfo.getDeptId(), SysRoleDistributeBindEnum.RB_MARKET_PROXY_EMPLOYEE
                            .getSysRoleCode(), DistributeSaleRoleEnum.ROLE_DSPD_EMP.getCode());
                DistributeNodeBaseCreateDto distributeNodeBaseCreateDto = DistributeNodeBaseCreateDto.builder()
                    .userType(DistributeNodePropEnum.TYPE_E.getProp())
                    .distributeType(DistributeTypeEnum.TYPE_SALE.getType())
                    .userId(distributePersonUserCreateDto.getUserId())
                    .adminUserId(distributePersonUserCreateDto.getUpLevelUserId())
                    .upLevelUserId(distributePersonUserCreateDto.getUpLevelUserId())
                    .percentStable(BigDecimal.ZERO)
                    .distributeRoleCode(DistributeSaleRoleEnum.ROLE_DSPD_EMP.getCode())
                    .distributeRoleLevel(DistributeSaleRoleEnum.ROLE_DSPD_EMP.getDistributeLevel())
                    .build();
                distributeNodeRoleChainDomainService
                    .createDistributeNodeAndRoleChainAfterClean(distributeNodeBaseCreateDto);
                updateNodeInfoAfterCreate(distributePersonUserCreateDto, DistributeTypeEnum.TYPE_SALE.getType());
            } else {
                return TransResult.fail("创建加盟商员工出错：上级不是加盟商");
            }
        } else {
            return TransResult.fail(checkSaleNodeCreate.getMessage());
        }

        return TransResult.success("加盟商员工创建成功");
    }

    /**
     * method : createSaleDistributeJmsAndRoleChain
     * description : 成为加盟商，除市场经理和加盟商本身，其他可以成为加盟商。
     * 注意：用户原来的邀请关系，需要更新，
     * 
     * @param distributeMemberCreateDto \{@link DistributeNodeInfoCreateDto \}
     * @return : cn.shengchao.examstar.base.TransResult<java.lang.String>
     * @author : Xiong weiqiang
     * @CreateDate : 2025-03-31 00:00:26
     * 
     * @Reviewed :
     * @UpdateLog : Name Date Reason/Contents
     *            ---------------------------------------
     *            **** **** ****
     *
     */

    @Transactional
    @Override
    public TransResult<String> createSaleDistributeJmsAndRoleChain(DistributeNodeInfoCreateDto distributeMemberCreateDto) {
        DistributeRoleDefaultPercent distributeRoleDefaultPercent = distributeRoleDefaultPercentService
            .getSalePercentByRoleCode(DistributeSaleRoleEnum.ROLE_DSPD.getCode());
        if (distributeRoleDefaultPercent == null || distributeRoleDefaultPercent.getPercentStable() == null) {
            return TransResult.fail("创建加盟商出错：查询加盟商默认分成比例错误");
        }
        TransResult<DistributeNodeRoleChainExistModel> checkSaleNodeCreate = distributeNodeRoleChainExistLoader
            .checkSaleNodeCreate(distributeMemberCreateDto.getUserId(), DistributeSaleRoleEnum.ROLE_DSPD);
        if (checkSaleNodeCreate.getSuccess()) {
            if (!UserCs.PLATFORM_USER_ID.equals(distributeMemberCreateDto.getUpLevelUserId())) {
                DistributeNodeRoleChainExistModel existModelForUpLevel = distributeNodeRoleChainExistLoader
                    .loadModelByUserIdByDeptChain(distributeMemberCreateDto.getUpLevelUserId(), DistributeTypeEnum.TYPE_SALE);
                //加盟商的非0上级只能说是市场经理
                if (existModelForUpLevel.getDistributeNodeInfo() != null && !existModelForUpLevel
                    .getDistributeNodeInfo()
                    .getDistributeRoleCode()
                    .equals(DistributeSaleRoleEnum.ROLE_MKMG.getCode())) {
                    return TransResult.fail("创建加盟商出错：非平台上架只能是市场经理");
                }

            }
            DistributeNodeRoleChainExistModel existModelForUser = distributeNodeRoleChainExistLoader
                .loadModelByUserIdByDeptChain(distributeMemberCreateDto.getUserId(), DistributeTypeEnum.TYPE_SALE);
//                不用更新邀请关系，不然加盟商就抢了邀请关系，会员空了。还有就是邀请关系现在是要企微号的，不好设置
//            //如果不是会员的话，要更新邀请关系。
//            if (existModelForUser.getDistributeNodeInfo() != null && !existModelForUser.getDistributeNodeInfo()
//                .getDistributeRoleCode()
//                .equals(DistributeSaleRoleEnum.ROLE_SLMB.getCode())) {
//                userInviteService.batchUpdateUserInviteRecordForJms(distributeMemberCreateDto
//                    .getUserId(), distributeMemberCreateDto.getUpLevelUserId());
//            }
            //加盟商的系统挂载点，创建部门，创建部门关系
            Dept deptRoot = deptRepository.getDeptById(DistributeDeptInnerRootEnum.SALE_JMS.getDeptId());
            List<DistributeDeptInfo> distributeDeptInfos=distributeDeptInfoService
                    .list(Wrappers.lambdaQuery(DistributeDeptInfo.class).eq(DistributeDeptInfo::getDistributeType,DistributeTypeEnum.TYPE_SALE.getType())
                            .eq(DistributeDeptInfo::getDataStatus,DistributeDataStatusEnum.STATUS_CURT.getStatus())
                            .eq(DistributeDeptInfo::getDeptOwnerId,distributeMemberCreateDto.getUserId())
                    );
            //如果有部门，则直接使用，如果没有，则创建部门
            Long deptId=0L;
            if (CollUtil.isNotEmpty(distributeDeptInfos)&&distributeDeptInfos.size()>1){
                throw new RuntimeException("用户"+distributeMemberCreateDto.getUserType()+"推广分销商只能有一个部门");
            }else if (CollUtil.isNotEmpty(distributeDeptInfos)&&distributeDeptInfos.size()==1){
                deptId=distributeDeptInfos.getFirst().getDeptId();
            }else{
                Dept dept = new Dept();
                dept.setAncestors("0," + deptRoot.getId());
                dept.setParentId(deptRoot.getId());
                dept.setName(distributeMemberCreateDto.getFullName());
                dept.setIsSystem(Boolean.TRUE);
                dept.setSort(999);
                dept.setDescription(distributeMemberCreateDto.getFullName());
                dept.setStatus(DisEnableStatusEnum.ENABLE);
                dept = deptRepository.createNewDept(dept);
                deptId=dept.getId();
            }
            //现有分销部门的历史状态改为历史
            distributeDeptInfoService.update(Wrappers.lambdaUpdate(DistributeDeptInfo.class)
                    .eq(DistributeDeptInfo::getDistributeType,DistributeTypeEnum.TYPE_SALE.getType())
                    .eq(DistributeDeptInfo::getDataStatus,DistributeDataStatusEnum.STATUS_CURT.getStatus())
                    .eq(DistributeDeptInfo::getDeptOwnerId,distributeMemberCreateDto.getUserId())
                    .set(DistributeDeptInfo::getDataStatus,DistributeDataStatusEnum.STATUS_HIS.getStatus())
            );

            DistributeDeptInfo distributeDeptInfo = new DistributeDeptInfo();
            distributeDeptInfo.setDeptId(deptId);
            distributeDeptInfo.setDeptOwnerId(distributeMemberCreateDto.getUserId());
            //前面判断了市场经理，如果是上级不是平台，则上级是市场经理
            distributeDeptInfo.setUpLevelUserId(distributeMemberCreateDto.getUpLevelUserId());
            distributeDeptInfo.setDistributeType(DistributeTypeEnum.TYPE_SALE.getType());
            distributeDeptInfo.setDataStatus(DistributeDataStatusEnum.STATUS_CURT.getStatus());
            distributeDeptInfoService.save(distributeDeptInfo);
            //切换分销关系的部门。

            userRepository.updateUserDept(distributeMemberCreateDto
                    .getUserId(), distributeDeptInfo.getDeptId());
            distributeDeptUserRoleBindService
                    .processUserDeptRole(DistributeTypeEnum.TYPE_SALE, distributeMemberCreateDto
                            .getUserId(), distributeDeptInfo.getDeptId(), SysRoleDistributeBindEnum.RB_MARKET_PROXY_MANAGER.getSysRoleCode(),
                            DistributeSaleRoleEnum.ROLE_DSPD.getCode());

            DistributeNodeBaseCreateDto distributeNodeBaseCreateDto = DistributeNodeBaseCreateDto.builder()
                .userType(distributeMemberCreateDto.getUserType())
                .distributeType(DistributeTypeEnum.TYPE_SALE.getType())
                .userId(distributeMemberCreateDto.getUserId())
                .adminUserId(distributeMemberCreateDto.getUserId())
                .percentStable(distributeRoleDefaultPercent.getPercentStable())
                .distributeRoleCode(DistributeSaleRoleEnum.ROLE_DSPD.getCode())
                .distributeRoleLevel(DistributeSaleRoleEnum.ROLE_DSPD.getDistributeLevel())
                .upLevelUserId(distributeMemberCreateDto.getUpLevelUserId())
                .build();
            distributeNodeRoleChainDomainService
                .createDistributeNodeAndRoleChainAfterClean(distributeNodeBaseCreateDto);
            updateNodeInfoAfterCreate(distributeMemberCreateDto, DistributeTypeEnum.TYPE_SALE.getType());
        } else {
            return TransResult.fail(checkSaleNodeCreate.getMessage());
        }

        return TransResult.success("加盟商创建成功");
    }

    /**
     * method : createSaleDistributeMarketManagerAndRoleChain
     * description : 添加市场经理
     * 注意：用户成为市场经理，必须是另外建普通用户，不然避免不了市场经理和学员的邀请关系，
     * 如果原来是加盟商的，那么让他们新建一个账号做市场经理，然后把他原来的加盟商，调节到新市场经理名下，这样才可以避免市场经理和学员的邀请关系。
     * 
     * @param distributePersonUserCreateDto \{@link DistributeNodeInfoCreateDto \}
     * @return : cn.shengchao.examstar.base.TransResult<java.lang.String>
     * @author : Xiong weiqiang
     * @CreateDate : 2025-03-31 00:36:54
     *
     * @Reviewed :
     * @UpdateLog : Name Date Reason/Contents
     *            ---------------------------------------
     *            **** **** ****
     *
     */
    @Transactional
    @Override
    public TransResult<String> createSaleDistributeMarketManagerAndRoleChain(DistributePersonUserCreateDto distributePersonUserCreateDto) {
        DistributeRoleDefaultPercent distributeRoleDefaultPercent = distributeRoleDefaultPercentService
            .getSalePercentByRoleCode(DistributeSaleRoleEnum.ROLE_MKMG.getCode());
        if (distributeRoleDefaultPercent == null || distributeRoleDefaultPercent.getPercentStable() == null) {
            return TransResult.fail("创建市场经理出错：查询加盟商默认分成比例错误");
        }
        TransResult<DistributeNodeRoleChainExistModel> checkSaleNodeCreate = distributeNodeRoleChainExistLoader
            .checkSaleNodeCreate(distributePersonUserCreateDto.getUserId(), DistributeSaleRoleEnum.ROLE_MKMG);
        if (checkSaleNodeCreate.getSuccess()) {
            DistributeNodeRoleChainExistModel existModelForUser = distributeNodeRoleChainExistLoader
                .loadModelByUserIdByDeptChain(distributePersonUserCreateDto.getUserId(), DistributeTypeEnum.TYPE_SALE);
            //如果不是新号的话
            if (existModelForUser.getDistributeNodeInfo() != null) {
                return TransResult.fail("创建市场经理出错：市场经理创建只能是新号，不然杜绝不了学员关系");
            }

            Dept deptRoot = deptRepository.getDeptById(DistributeDeptInnerRootEnum.SALE_SCJL.getDeptId());
            //切换分销关系的部门。
            userRepository.updateUserDept(distributePersonUserCreateDto
                    .getUserId(), deptRoot.getId());
            distributeDeptUserRoleBindService
                .processUserDeptRole(DistributeTypeEnum.TYPE_SALE, distributePersonUserCreateDto.getUserId(), deptRoot
                    .getId(), SysRoleDistributeBindEnum.RB_MARKET_MANAGER
                        .getSysRoleCode(), DistributeSaleRoleEnum.ROLE_MKMG.getCode());
            DistributeNodeBaseCreateDto distributeNodeBaseCreateDto = DistributeNodeBaseCreateDto.builder()
                .userType(DistributeNodePropEnum.TYPE_P.getProp())
                .userId(distributePersonUserCreateDto.getUserId())
                .distributeType(DistributeTypeEnum.TYPE_SALE.getType())
                .adminUserId(distributePersonUserCreateDto.getUpLevelUserId())
                //上级是平台
                .upLevelUserId(UserCs.PLATFORM_USER_ID)
                .percentStable(distributeRoleDefaultPercent.getPercentStable())
                .distributeRoleCode(DistributeSaleRoleEnum.ROLE_MKMG.getCode())
                .distributeRoleLevel(DistributeSaleRoleEnum.ROLE_MKMG.getDistributeLevel())
                .build();
            distributeNodeRoleChainDomainService
                .createDistributeNodeAndRoleChainAfterClean(distributeNodeBaseCreateDto);
            updateNodeInfoAfterCreate(distributePersonUserCreateDto, DistributeTypeEnum.TYPE_SALE.getType());
        } else {
            return TransResult.fail(checkSaleNodeCreate.getMessage());
        }

        return TransResult.success("市场经理创建成功");
    }

    /**
     * @ClassName : PlatformUserArchBIService
     *            description : 内容分销员工，只能说普通用户;一个签约老师当员工，并不能多拿内容的分成。
     * @author : Xiong weiqiang
     * @CreateDate : 2025-03-31 01:01:37
     * @version : V1.0.0
     *
     */
    @Transactional
    @Override
    public TransResult<String> createContentDistributeJmsygAndRoleChain(DistributePersonUserCreateDto distributePersonUserCreateDto) {
        TransResult<DistributeNodeRoleChainExistModel> checkContentNodeCreate = distributeNodeRoleChainExistLoader
            .checkContentNodeCreate(distributePersonUserCreateDto.getUserId(), DistributeContentRoleEnum.ROLE_CTPD_EMP);
        if (checkContentNodeCreate.getSuccess()) {
            //加盟商的部门
            Long deptId = distributeDeptUserRoleBindService.getDeptBindIdForUser(distributePersonUserCreateDto
                .getUpLevelUserId(), DistributeTypeEnum.TYPE_CTPD);
            if (deptId == null) {
                return TransResult.fail("创建内容分销商员工出错：未查询到内容分销商部门id");
            }
            //如果是加盟商，上级还是加盟商部门的管理员，不是的话那么上级就是平台管理员。
            //DistributeDeptInfo distributeDeptInfo = distributeDeptInfoService.getById(deptId);
            DistributeDeptInfo distributeDeptInfo = distributeDeptInfoService.getOne(Wrappers.lambdaQuery(DistributeDeptInfo.class)
                    .eq(DistributeDeptInfo::getDeptId, deptId).eq(DistributeDeptInfo::getDataStatus,DistributeDataStatusEnum.STATUS_CURT.getStatus())
            );
            if (distributeDeptInfo == null) {
                return TransResult.fail("创建内容分销商员工出错：未查询到内容分销商部门");
            }
            //切换内容分销关系的部门。
            userRepository.updateUserDept(distributePersonUserCreateDto
                    .getUserId(), distributeDeptInfo.getDeptId());
            distributeDeptUserRoleBindService
                .processUserDeptRole(DistributeTypeEnum.TYPE_CTPD, distributePersonUserCreateDto
                    .getUserId(), distributeDeptInfo.getDeptId(), SysRoleDistributeBindEnum.RB_CONTENT_EMPLOYEE
                        .getSysRoleCode(), DistributeContentRoleEnum.ROLE_CTPD_EMP.getCode());
            DistributeNodeBaseCreateDto distributeNodeBaseCreateDto = DistributeNodeBaseCreateDto.builder()
                .userType(DistributeNodePropEnum.TYPE_E.getProp())
                .userId(distributePersonUserCreateDto.getUserId())
                .distributeType(DistributeTypeEnum.TYPE_CTPD.getType())
                .adminUserId(distributePersonUserCreateDto.getUpLevelUserId())
                //上级是平台
                .upLevelUserId(distributePersonUserCreateDto.getUpLevelUserId())
                .percentStable(BigDecimal.ZERO)
                .distributeRoleCode(DistributeContentRoleEnum.ROLE_CTPD_EMP.getCode())
                .distributeRoleLevel(DistributeContentRoleEnum.ROLE_CTPD_EMP.getDistributeLevel())
                .build();
            distributeNodeRoleChainDomainService
                .createDistributeNodeAndRoleChainAfterClean(distributeNodeBaseCreateDto);

            updateNodeInfoAfterCreate(distributePersonUserCreateDto, DistributeTypeEnum.TYPE_CTPD.getType());
        }
        return TransResult.success("内容分销员工创建成功");
    }

    @Transactional
    @Override
    public TransResult<String> createContentDistributeJmsAndRoleChain(DistributeNodeInfoCreateDto distributeMemberCreateDto) {
        //内容分销商按课程进行分成，没有默认分成比例
        TransResult<DistributeNodeRoleChainExistModel> checkContentNodeCreate = distributeNodeRoleChainExistLoader
            .checkContentNodeCreate(distributeMemberCreateDto.getUserId(), DistributeContentRoleEnum.ROLE_CTPD);
        if (checkContentNodeCreate.getSuccess()) {
            //加盟商的系统挂载点，创建部门，创建部门关系
            Dept deptRoot = deptRepository.getDeptById(DistributeDeptInnerRootEnum.CONTENT_JMS.getDeptId());
            List<DistributeDeptInfo> distributeDeptInfos=distributeDeptInfoService
                    .list(Wrappers.lambdaQuery(DistributeDeptInfo.class).eq(DistributeDeptInfo::getDistributeType,DistributeTypeEnum.TYPE_CTPD.getType())
                            .eq(DistributeDeptInfo::getDataStatus,DistributeDataStatusEnum.STATUS_CURT.getStatus())
                            .eq(DistributeDeptInfo::getDeptOwnerId,distributeMemberCreateDto.getUserId())
                    );
            Long deptId=0L;
            if (CollUtil.isNotEmpty(distributeDeptInfos)&&distributeDeptInfos.size()>1){
                throw new RuntimeException("用户"+distributeMemberCreateDto.getUserId()+"内容分销商只能有一个部门");
            }else if (CollUtil.isNotEmpty(distributeDeptInfos)&&distributeDeptInfos.size()==1){
                deptId=distributeDeptInfos.getFirst().getDeptId();
            }else{
                Dept dept = new Dept();
                dept.setAncestors("0," + deptRoot.getId());
                dept.setParentId(deptRoot.getId());
                dept.setName(distributeMemberCreateDto.getFullName());
                dept.setIsSystem(Boolean.TRUE);
                dept.setSort(999);
                dept.setDescription(distributeMemberCreateDto.getFullName());
                dept.setStatus(DisEnableStatusEnum.ENABLE);
                dept = deptRepository.createNewDept(dept);
                deptId=dept.getId();
            }
            //现有分销部门的历史状态改为历史
            distributeDeptInfoService.update(Wrappers.lambdaUpdate(DistributeDeptInfo.class)
                    .eq(DistributeDeptInfo::getDistributeType,DistributeTypeEnum.TYPE_CTPD.getType())
                    .eq(DistributeDeptInfo::getDataStatus,DistributeDataStatusEnum.STATUS_CURT.getStatus())
                    .eq(DistributeDeptInfo::getDeptOwnerId,distributeMemberCreateDto.getUserId())
                    .set(DistributeDeptInfo::getDataStatus,DistributeDataStatusEnum.STATUS_HIS.getStatus())
            );
            DistributeDeptInfo distributeDeptInfo = new DistributeDeptInfo();
            distributeDeptInfo.setDeptId(deptId);
            distributeDeptInfo.setDeptOwnerId(distributeMemberCreateDto.getUserId());
            //前面判断了市场经理，如果是上级不是平台，则上级是市场经理
            distributeDeptInfo.setUpLevelUserId(distributeMemberCreateDto.getUpLevelUserId());
            distributeDeptInfo.setDistributeType(DistributeTypeEnum.TYPE_CTPD.getType());
            distributeDeptInfo.setDataStatus(DistributeDataStatusEnum.STATUS_CURT.getStatus());
            distributeDeptInfoService.save(distributeDeptInfo);

            //切换分销关系的部门。

            userRepository.updateUserDept(distributeMemberCreateDto
                    .getUserId(), distributeDeptInfo.getDeptId());
            distributeDeptUserRoleBindService
                .processUserDeptRole(DistributeTypeEnum.TYPE_CTPD, distributeMemberCreateDto
                    .getUserId(), distributeDeptInfo.getDeptId(), SysRoleDistributeBindEnum.RB_CONTENT_MANAGER
                        .getSysRoleCode(), DistributeContentRoleEnum.ROLE_CTPD.getCode());
            DistributeNodeBaseCreateDto distributeNodeBaseCreateDto = DistributeNodeBaseCreateDto.builder()
                .userType(distributeMemberCreateDto.getUserType())
                .distributeType(DistributeTypeEnum.TYPE_CTPD.getType())
                .userId(distributeMemberCreateDto.getUserId())
                .adminUserId(distributeMemberCreateDto.getUserId())
                .percentStable(BigDecimal.ZERO)
                .distributeRoleCode(DistributeContentRoleEnum.ROLE_CTPD.getCode())
                .distributeRoleLevel(DistributeContentRoleEnum.ROLE_CTPD.getDistributeLevel())
                .upLevelUserId(distributeMemberCreateDto.getUpLevelUserId())
                .build();
            distributeNodeRoleChainDomainService
                .createDistributeNodeAndRoleChainAfterClean(distributeNodeBaseCreateDto);
            updateNodeInfoAfterCreate(distributeMemberCreateDto, DistributeTypeEnum.TYPE_CTPD.getType());
            return TransResult.success("内容分销员商创建成功");
        } else {
            return TransResult.fail("创建内容分销商出错：内容分销商已经存在");
        }

    }


    @Override
    public DistributeUserBankVo getDistributeUserBankVo(Long userId, Integer distributeType) {
        List<DistributeUserBank> distributeUserBanks = distributeUserBankService.list(Wrappers.lambdaQuery(DistributeUserBank.class).eq(DistributeUserBank::getUserId, userId).eq(DistributeUserBank::getDistributeType, distributeType));
        DistributeUserBankVo distributeUserBank = new DistributeUserBankVo();
        if (distributeUserBanks.isEmpty()){
            distributeUserBank.setUserId(userId);
            distributeUserBank.setDistributeType(distributeType);
            return distributeUserBank;
        }
        return BeanUtil.copyProperties(distributeUserBanks.getFirst(), DistributeUserBankVo.class);
    }
    @Transactional
    @Override
    public void saveDistributeUserBank(DistributeUserBankSaveDto distributeUserBankSaveDto) {
        distributeUserBankService.remove(Wrappers.lambdaQuery(DistributeUserBank.class).eq(DistributeUserBank::getUserId, distributeUserBankSaveDto.getUserId()).eq(DistributeUserBank::getDistributeType, distributeUserBankSaveDto.getDistributeType()));
        DistributeUserBank distributeUserBank = BeanUtil.copyProperties(distributeUserBankSaveDto, DistributeUserBank.class);
        distributeUserBankService.save(distributeUserBank);

    }

    private void updateNodeInfoAfterCreate(DistributePersonUserCreateDto distributePersonUserCreateDto,Integer distributeType) {
        distributeNodeInfoService.update(Wrappers.lambdaUpdate(DistributeNodeInfo.class)
                .eq(DistributeNodeInfo::getUserId, distributePersonUserCreateDto.getUserId())
                .eq(DistributeNodeInfo::getDistributeType, distributeType)
                .eq(DistributeNodeInfo::getDataStatus, DistributeDataStatusEnum.STATUS_CURT.getStatus())
                .set(DistributeNodeInfo::getDistributeRoleCode, distributePersonUserCreateDto.getDistributeRoleCode())
                .set(StrUtil.isNotBlank(distributePersonUserCreateDto.getShortName()),DistributeNodeInfo::getShortName, distributePersonUserCreateDto.getShortName())
                .set(StrUtil.isNotBlank(distributePersonUserCreateDto.getFullName()),DistributeNodeInfo::getFullName, distributePersonUserCreateDto.getFullName())
                .set(StrUtil.isNotBlank(distributePersonUserCreateDto.getContactMan()),DistributeNodeInfo::getContactMan, distributePersonUserCreateDto.getContactMan())
                .set(StrUtil.isNotBlank(distributePersonUserCreateDto.getContactPhone()),DistributeNodeInfo::getContactPhone, distributePersonUserCreateDto.getContactPhone())
                .set(StrUtil.isNotBlank(distributePersonUserCreateDto.getPInLaw()),DistributeNodeInfo::getPInLaw, distributePersonUserCreateDto.getPInLaw())
                .set(StrUtil.isNotBlank(distributePersonUserCreateDto.getLicNo()),DistributeNodeInfo::getLicNo, distributePersonUserCreateDto.getLicNo())
        );
    }
    private void updateNodeInfoAfterCreate(DistributeNodeInfoCreateDto distributeNodeInfoCreateDto,Integer distributeType) {
        distributeNodeInfoService.update(Wrappers.lambdaUpdate(DistributeNodeInfo.class)
                .eq(DistributeNodeInfo::getUserId, distributeNodeInfoCreateDto.getUserId())
                .eq(DistributeNodeInfo::getDistributeType, distributeType)
                .eq(DistributeNodeInfo::getDataStatus, DistributeDataStatusEnum.STATUS_CURT.getStatus())
                .set(DistributeNodeInfo::getDistributeRoleCode, distributeNodeInfoCreateDto.getDistributeRoleCode())
                .set(StrUtil.isNotBlank(distributeNodeInfoCreateDto.getShortName()),DistributeNodeInfo::getShortName, distributeNodeInfoCreateDto.getShortName())
                .set(StrUtil.isNotBlank(distributeNodeInfoCreateDto.getFullName()),DistributeNodeInfo::getFullName, distributeNodeInfoCreateDto.getFullName())
                .set(StrUtil.isNotBlank(distributeNodeInfoCreateDto.getContactMan()),DistributeNodeInfo::getContactMan, distributeNodeInfoCreateDto.getContactMan())
                .set(StrUtil.isNotBlank(distributeNodeInfoCreateDto.getContactPhone()),DistributeNodeInfo::getContactPhone, distributeNodeInfoCreateDto.getContactPhone())
                .set(StrUtil.isNotBlank(distributeNodeInfoCreateDto.getPInLaw()),DistributeNodeInfo::getPInLaw, distributeNodeInfoCreateDto.getPInLaw())
                .set(StrUtil.isNotBlank(distributeNodeInfoCreateDto.getLicNo()),DistributeNodeInfo::getLicNo, distributeNodeInfoCreateDto.getLicNo())
        );
    }
}